package cn.myframe.entity.sys;

import cn.myframe.log.LogPojo;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 
 * 系统日志实体
 * 
 * @author  ynz
 * @email   ynz@myframe.cn
 * @version 创建时间：2018年6月8日 上午8:48:43
 */
@TableName("SYS_LOG")
public class SysLogEntity implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private Long id;
	//用户名
	@TableField("USER_NAME")
	private String username;
	//用户操作
	private String operation;
	//请求方法
	private String method;
	//请求参数
	private String params;
	//IP地址
	private String ip;
	//创建时间
	@TableField("CREATE_DATE")
	private Date createDate;
	//日志类型
	private int type;
	//创建人ID
	@TableField("CREATE_BY")
	private Long createBy;
	//访问结果
	@TableField("RESULT")
	private String result;
	//请求的类名
	@TableField("CLASS_NAME")
	private String className;
	@TableField("OPERATE_VALUE")
	private String operateValue;
	@TableField("UPDATE_OLD")
	private String updateOld;
	@TableField(exist = false)
	private String url;

	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	/**
	 * 设置：
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * 获取：
	 */
	public Long getId() {
		return id;
	}
	/**
	 * 设置：用户名
	 */
	public void setUsername(String username) {
		this.username = username;
	}
	/**
	 * 获取：用户名
	 */
	public String getUsername() {
		return username;
	}
	/**
	 * 设置：用户操作
	 */
	public void setOperation(String operation) {
		this.operation = operation;
	}
	/**
	 * 获取：用户操作
	 */
	public String getOperation() {
		return operation;
	}
	/**
	 * 设置：请求方法
	 */
	public void setMethod(String method) {
		this.method = method;
	}
	/**
	 * 获取：请求方法
	 */
	public String getMethod() {
		return method;
	}
	/**
	 * 设置：请求参数
	 */
	public void setParams(String params) {
		this.params = params;
	}
	/**
	 * 获取：请求参数
	 */
	public String getParams() {
		return params;
	}
	/**
	 * 设置：IP地址
	 */
	public void setIp(String ip) {
		this.ip = ip;
	}
	/**
	 * 获取：IP地址
	 */
	public String getIp() {
		return ip;
	}
	/**
	 * 设置：创建时间
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	/**
	 * 获取：创建时间
	 */
	public Date getCreateDate() {
		return createDate;
	}
	
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public Long getCreateBy() {
		return createBy;
	}
	public void setCreateBy(Long createBy) {
		this.createBy = createBy;
	}
	public String getOperateValue() {
		return operateValue;
	}
	public void setOperateValue(String operateValue) {
		this.operateValue = operateValue;
	}
	public String getUpdateOld() {
		return updateOld;
	}
	public void setUpdateOld(String updateOld) {
		this.updateOld = updateOld;
	}
	public String getUrl() {
		if(!StringUtils.isEmpty(this.className)){
			String packageName = "";
			if(StringUtils.isNotEmpty(this.method)){
				String[] strs = this.method.split("\\.");
				if(strs.length>4){
					packageName = strs[3];
				}
			}
			String page = packageName + "/" + this.className.replace("Controller", "").toLowerCase();
			if (page.contains("sysuserinfo")) {
				return page + "log.html";
			}
			return page + ".html";
		}
		return "";
	}
	
	public SysLogEntity(){
		
	}
	
	public SysLogEntity(LogPojo logPojo){
		if(logPojo != null){
			this.username = logPojo.getUsername();
			this.method = logPojo.getMethod();
			this.params = logPojo.getParams();
			this.className = logPojo.getClassName();
			this.operateValue = logPojo.getOperateValue();
			this.updateOld = logPojo.getUpdateOld();
			this.type = logPojo.getType();
			this.ip = logPojo.getIp();
			this.operation = logPojo.getOperation();
			this.result = logPojo.getResult();
		}
	}
	
	
}
